package cn.edu.mju.property.web.controller;

import cn.edu.mju.property.service.impl.ComplaintServiceImpl;
import cn.edu.mju.property.service.ComplaintService;
import com.alibaba.fastjson.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet( "/DelComplaint")
public class DelComplaint extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        String ids = request.getParameter("ids");
        ComplaintService service = new ComplaintServiceImpl();
        boolean flag = service.delCompaint(JSONArray.parseArray(ids));
        if(flag){
            response.getWriter().write("success");
        }else {
            response.getWriter().write("error");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String id = request.getParameter("id");
        ComplaintService service = new ComplaintServiceImpl();
        boolean flag = service.delCompaint(JSONArray.parseArray("["+id+"]"));
        if(flag){
            response.getWriter().write("success");
        }else {
            response.getWriter().write("error");
        }

    }
}
